﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.Web;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
using System.Data;
using System.IO;
using MBSProcessComponent;
namespace MBS
{
    public partial class FoodRevenueReport : System.Web.UI.Page
    {
        ReportDocument objReport = new ReportDocument();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
               
            }
        }

       

        protected void btnReport_Click(object sender, EventArgs e)
        {
            DataSet dsReport = new DataSet();
           // DateTime StartDate =(DateTime) startDateCalendar.SelectedDate;
            //DateTime EndDate = (DateTime)endDateCalendar.SelectedDate;
            MBSBLC.BLC blc = new MBSBLC.BLC();
            dsReport = blc.GetFoodCategoryWiseRep(StartDateTextBox.Text, EndDateTextBox.Text);
            if (dsReport != null){
            objReport.Load(Server.MapPath("~/CrystalReports/crpFoodRevenue.rpt"));
            objReport.SetDataSource(dsReport.Tables[0]);
            System.IO.MemoryStream s = (MemoryStream)objReport.ExportToStream(ExportFormatType.PortableDocFormat);
            var _with1 = HttpContext.Current.Response;
            _with1.ClearContent();
            _with1.ClearHeaders();
            _with1.ContentType = "application/pdf";
            _with1.AddHeader("Content-Disposition", "inline; filename=Report.pdf");
            _with1.BinaryWrite(s.ToArray());
            _with1.End();
            // rptDoc.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
            //rptDoc.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, HttpContext.Current.Response, true, "JobOrderList Report");
            crpViewerMovie.ReportSource = objReport;
            }
            else
            {
                string noReport = "Report for the selected dates is not available";
                ClientScript.RegisterStartupScript(this.GetType(), "sad", "javascript:showAlert('" + noReport + "')", true);
            }
        }
        protected void startDateCalendar_SelectionChanged(object sender, EventArgs e)
        {
            StartDateTextBox.Text = startDateCalendar.SelectedDate.ToString();
            //startDateCalendar.Style.Add("display","none");
            
        }

        protected void endDateCalendar_SelectionChanged(object sender, EventArgs e)
        {
            EndDateTextBox.Text = endDateCalendar.SelectedDate.ToString();
        }
    }
}